package indoor.nexd.com.nexdmap.application;

import android.app.Application;
import android.util.Log;

import com.litesuits.orm.LiteOrm;
import com.litesuits.orm.db.DataBase;
import com.tencent.stat.MtaSDkException;
import com.tencent.stat.StatConfig;
import com.tencent.stat.StatService;
import com.tencent.stat.common.StatConstants;

import java.util.ArrayList;

import indoor.nexd.com.nexdmap.model.MallModel;


/**
 * Created by lawrence on 2015/11/9.
 */
public class MyApplication extends Application {

    public static final ArrayList<MallModel> mallList = new ArrayList<>();
    private static final String TAG = MyApplication.class.getSimpleName();

    public static boolean IS_MAP = false; // 是否允许 Map
    public static boolean IS_WIFI = false; // 是否允许 Wi-Fi
    public static boolean IS_BEACON = false; // 是否允许 蓝牙
    public static boolean IS_ROUTE_PLAN = false; // 是否允许路径规划

    // Test Param
    public static boolean IS_TEST_MODE = false; // 是否为测试模式
    public static boolean AUTO_CHANGE_FLOOR = false; // 是否自动切换楼层
    public static boolean IS_SMOOTH_OUTPUT = false; // 是否允许平滑输出
    public static int LOCATION_TIME = 1; // 默认时间1s

    public static String userId = ""; // 用户 ID
    private static MyApplication mInstance; // 当前 Application 实例
    private static DataBase liteOrm; // 数据库对象
    public static final String APP_KEY = "f4b5aeaa1776f7af714e0663fa2e50b2"; // APP_KEY http 必须带的参数

    // 获取当前实例
    public static synchronized MyApplication getInstance() {
        return mInstance;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;
        //在使用SDK各组件之前初始化context信息，传入ApplicationContext
        //注意该方法要再setContentView方法之前实现

        // 初始化异常监听
        StatConfig.setAutoExceptionCaught(true);
        StatConfig.setDebugEnable(true);
        StatConfig.setAppKey(this, "AZQZ6W621YHM");
        StatConfig.setInstallChannel(this, "private");
        try {
            StatService.startStatService(this, null, StatConstants.VERSION);
        } catch (MtaSDkException e) {
            reportException(e);
        }

    }

    public static DataBase getLiteOrm() {
        if (liteOrm == null) {
            synchronized (mInstance) {
                if (liteOrm == null) {
                    liteOrm = LiteOrm.newSingleInstance(mInstance, "nexdmap.db");
                    Log.d(TAG, "getLiteOrm: 初始化成功!");
                }
            }
        }
        return liteOrm;
    }

    public void reportException(Throwable e) {
        e.printStackTrace();
        StatService.reportException(this, e);
    }
}
